﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO.Ports;

namespace photoremote
{
    public partial class Form1 : Form
    {
        SerialPort serialPort1;

        public Form1()
        {
            InitializeComponent();
        }

        private void panel1_Paint(object sender, PaintEventArgs e)
        {

        }

        private void timer1_Tick(object sender, EventArgs e)
        {

        }

        private void button2_Click(object sender, EventArgs e)
        {

        }

        private void Form1_Load(object sender, EventArgs e)
        {
            string[] availablePorts = System.IO.Ports.SerialPort.GetPortNames();
            cbPorts.Items.Clear();
            cbPorts.Items.AddRange(availablePorts);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            textBox1.Text = cbPorts.SelectedItem.ToString();
            serialPort1.PortName = cbPorts.SelectedItem.ToString();
            serialPort1.BaudRate = 9600;
            serialPort1.Open();   
        }

        private void Form1_FormClosed(object sender, FormClosedEventArgs e)
        {

        }

        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (serialPort1.IsOpen) serialPort1.Close();
        }
    }
}
